home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-03-06 | 3.3 KB | 114 lines | [TEXT/GEOL] |
- Item 5976813 18-Jan-91 05:17PST
-
- From: AUST0134 Jam Software Sydney,IVR
-
- To: POWERUP.DEV Power Up Software,PRT
-
- cc: MACAPP.TECH$ MacApp Technical
-
- ------------------------------------------------------------------------------
-
- Sub: TAspectPicture x 2
-
- Here are two attempts at centering pictures within TPicture.
-
- The first one OVERRIDEs TPicture.Draw, and has no other effect than just to
- draw the picture in its original picFrame, centred within TPicture.
-
- The second one OVERRIDEs TControl.ControlArea, and so not only does the picture
- draw itself in the centre of the TPicture, mouseclicks will only count if they
- occur in the centred picture frame as well.
-
- CentreRectInRect is just a bonus utility which does what it says.
-
- PROCEDURE CenterRectInRect(VAR inner: Rect; outer: Rect; horiz, vert: Boolean);
- { centre the inner rect within the outer rect, either horizontally, or
- vertically, or both
- }
- VAR
- innerSize, outerSize: Point;
- BEGIN
- WITH outer DO
- SetPt(outerSize, right - left, bottom - top);
- WITH inner DO BEGIN
- SetPt(innerSize, right - left, bottom - top);
- IF horiz THEN
- left := outer.left + (outerSize.h - innerSize.h) DIV 2;
- IF vert THEN
- top := outer.top + (outerSize.v - innerSize.v) DIV 2;
- right := left + innerSize.h;
- bottom := top + innerSize.v;
- END;
- END;
-
- {-----------------------
- version 1
- ------------------------}
- TYPE
- TAspectPicture = OBJECT(TPicture)
- PROCEDURE Draw(area: Rect); OVERRIDE;
- END;
-
- PROCEDURE TAspectPicture.Draw(area: Rect); OVERRIDE;
- { Modified from TPicture.Draw just to grab the actual picture frame, and
- then centre this frame within the TPicture area before drawing it
- }
- VAR
- oldState: SignedByte;
- cntlFrame,
- myPicFrame: Rect;
- saveDataHandle: picHandle;
- BEGIN
- IF fDataHandle <> NIL THEN BEGIN
- IF fRsrcID <> kNoResource THEN
- LoadResource(Handle(fDataHandle));
- IF fDataHandle^ <> NIL THEN BEGIN { If there's room for the picture… }
- ControlArea(cntlFrame);
- myPicFrame := fDataHandle^^.picFrame;
- CenterRectInRect(myPicFrame,cntlFrame,TRUE,TRUE);
- oldState := GetHandleBits(Handle(fDataHandle));
- HNoPurge(Handle(fDataHandle));
- PenNormal;
- DrawPicture(fDataHandle, myPicFrame);
- SetHandleBits(Handle(fDataHandle), oldState);
- END;
- END;
- saveDataHandle := fDataHandle;
- fDataHandle := NIL;
- INHERITED Draw(area);
- fDataHandle := saveDataHandle;
- END;
-
- {-----------------------
- version 2
- ------------------------}
- TYPE
- TAspectPicture = OBJECT(TPicture)
- PROCEDURE ControlArea(VAR theArea: Rect); OVERRIDE;
- END;
-
- PROCEDURE TAspectPicture.ControlArea(VAR theArea: Rect); OVERRIDE;
- { Change the control area to just be the area of the original picFrame of
- the picture, centered within the TPicture control area.
- }
- VAR
- myPicFrame: Rect;
- BEGIN
- INHERITED ControlArea(theArea);
-
- IF fDataHandle <> NIL THEN BEGIN
- IF fRsrcID <> kNoResource THEN
- LoadResource(Handle(fDataHandle));
- IF fDataHandle^ <> NIL THEN BEGIN { If there's room for the picture… }
- myPicFrame := fDataHandle^^.picFrame;
- CenterRectInRect(myPicFrame,theArea,TRUE,TRUE);
- theArea := myPicFrame;
- END;
- END;
- END;
-
- Tseung Cheung
- JAM Software Pty Ltd
- ALink AUST0134
-
-